package com.e3.core.base;

import java.io.Serializable;
import java.util.Properties;

import org.hibernate.HibernateException;
import org.hibernate.MappingException;
import org.hibernate.dialect.Dialect;
import org.hibernate.engine.SessionImplementor;
import org.hibernate.id.Configurable;
import org.hibernate.id.IdentifierGenerator;
import org.hibernate.type.Type;

import com.e3.core.utils.PKgen;

public class EntityPKGenerator implements IdentifierGenerator,Configurable{
	
	private String entityName;

	public void configure(Type type, Properties params, Dialect d) throws MappingException {
		entityName = params.getProperty(ENTITY_NAME);
		if ( entityName == null ) {
			throw new MappingException("no entity name");
		}
	}

	public Serializable generate(SessionImplementor session, Object object)	throws HibernateException {
		return PKgen.getInstance().nextPK();
	}

}
